﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class ZJ_KHDWHZControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            if (!base.Page.IsPostBack) { QSDataDLL(); }
            Bind();
        }
        protected void btnSeach_Click(object sender, EventArgs e)
        {
            Bind();
        }
        protected void Bind()
        {
            CustomGridView CustomGridList1 = (CustomGridView)FindControl("CustomGridList1");
            Button btnSeach = (Button)FindControl("btnSeach");
            btnSeach.Click += new EventHandler(btnSeach_Click);
            DataTable dt = _EluZSDataProvider.GetKHCompanyHZ(GetStrWhere(), GetStrWhere1());
            CustomGridList1.DataSource = dt;
            CustomGridList1.RecordCount = dt.Rows.Count;
            CustomGridList1.PageSize = 10;
            CustomGridList1.DataBind();
            CustomGridList1.OnLoadData += new EventHandler(CustomGridList1_OnLoadData);
        }
        protected void CustomGridList1_OnLoadData(object sender, EventArgs e)
        {
            Bind();
        }
        protected string GetStrWhere()
        {
            MPCalendar tDate1 = (MPCalendar)FindControl("Calendar1");
            MPCalendar tDate2 = (MPCalendar)FindControl("Calendar2");
            string strWhere = string.Empty;
            if (!string.IsNullOrEmpty(tDate1.Text)) { strWhere += " and 时间>= to_date('" + tDate1.Text + "','yyyy-mm-dd')"; }
            if (!string.IsNullOrEmpty(tDate2.Text)) { strWhere += " and 时间< to_date('" + tDate2.Text + "','yyyy-mm-dd')"; }
            return strWhere;
        }
        protected string GetStrWhere1()
        {
            DropDownList DropDownList1 = (DropDownList)FindControl("DropDownList1");
            string strWhere = string.Empty;
            if (!string.IsNullOrEmpty(DropDownList1.SelectedValue)) { strWhere += "  and p1.区属='" + DropDownList1.SelectedValue + "'"; }
            return strWhere;
        }
        protected void QSDataDLL()
        {
            DropDownList DropDownList1 = (DropDownList)FindControl("DropDownList1");
            string sql = @"select keyname,keyvalue from zs_params where name ='区属'";
            List<EluZSProvider.Params> _params = _EluZSDataProvider.GetParams("区属");
            EluZSProvider.Params item = new Params();
            _params.Insert(0, item);
            DropDownList1.DataSource = _params;
            DropDownList1.DataValueField = "keyname";
            DropDownList1.DataTextField = "keyname";
            DropDownList1.DataBind();
        }
    }
}


